//
//  YCHomeCell.swift
//  weiBoSwift
//
//  Created by 刘胤辰 on 16/7/24.
//  Copyright © 2016年 it.com. All rights reserved.
//

import UIKit
import SnapKit

let marginW=10

class YCHomeCell: UITableViewCell {

    //创建三个子控件
    lazy var originalView:YCOriginalView=YCOriginalView()
    lazy var toolView:YCToolBarView=YCToolBarView()
    lazy var passOtherView:YCPassOtherView=YCPassOtherView()
    var toolBarConstraint:Constraint?
    
    //数据源
    var status:YCHomeStatus?{
        
        didSet{
            //给三个子控件赋值
            originalView.status=status
            passOtherView.status=status
            
            self.toolBarConstraint?.uninstall()
            
            if status?.retweeted_status==nil {
                self.toolView.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.toolBarConstraint=make.top.equalTo(originalView.snp_bottom).constraint
                    self.passOtherView.hidden=true
                })
            }else{
                
                self.toolView.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.toolBarConstraint=make.top.equalTo(passOtherView.snp_bottom).constraint
                    self.passOtherView.hidden=false
                })
            }
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        contentView.addSubview(originalView)
        contentView.addSubview(toolView)
        contentView.addSubview(passOtherView)
        
        //设置约束
        originalView.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.trailing.equalTo(contentView)
        }
        passOtherView.snp_makeConstraints { (make) -> Void in
            
            make.leading.trailing.equalTo(contentView)
            make.top.equalTo(originalView.snp_bottom)
        }
        toolView.snp_makeConstraints { (make) -> Void in
            
            make.leading.trailing.equalTo(contentView)
            self.toolBarConstraint = make.top.equalTo(passOtherView.snp_bottom).constraint
            make.height.equalTo(35)
        }
        contentView.snp_makeConstraints { (make) -> Void in
            
            make.leading.trailing.top.equalTo(self)
            make.bottom.equalTo(toolView)
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
